﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class staffeducation : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Membership.GetUser() != null)
        {
            string strUserName = Membership.GetUser().ToString();

            SqlConnection objConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["smsConnectionString"].ConnectionString);

            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select RoleName from aspnet_Users,aspnet_Roles,aspnet_UsersInRoles where aspnet_Users.UserId =aspnet_UsersInRoles. UserId and aspnet_UsersInRoles.RoleId = aspnet_Roles.RoleId and UserName = '" + strUserName + "'", objConnection);
            da.Fill(ds, "StaffinfoRole");
            DataTable dt1 = ds.Tables["StaffinfoRole"];


            SqlCommand objCommand = new SqlCommand("Users_FindDepartmentId", objConnection);
            objCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter objParameter = new SqlParameter("@UserName", SqlDbType.NVarChar);
            objCommand.Parameters.Add(objParameter);
            objParameter.Direction = ParameterDirection.Input;
            objParameter.Value = strUserName;

            SqlParameter objOutputParameter = new SqlParameter("@DepartmentID", SqlDbType.Int);
            objCommand.Parameters.Add(objOutputParameter);
            objOutputParameter.Direction = ParameterDirection.Output;

            objConnection.Open();

            objCommand.ExecuteNonQuery();
            Session["UserDepartmentID"] = (Int32)objOutputParameter.Value;

            ArrayList al = new ArrayList();
            for (int i = 0; i < dt1.Rows.Count; i++)
                al.Add(dt1.Rows[i].ItemArray[0]);

            Session["Role"] = al;
            Session["UserName"] = strUserName;
        }
    }
}
